package com.lancoo.znbkxx.teacher.aibkTestCoach.questionToEvaluation.aibkQuesEvalutionZW

import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.ABaseFragment
import android.text.Html
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.QuesEvaluationDetail
import com.lancoo.znbkxx.teacher.utils.WebStyleUtils
import com.lancoo.znbkxx.teacher.widget.CustomTextViewToPicture
import kotlinx.android.synthetic.main.aibk_adapter_item_itemanalysis.view.*
import kotlinx.android.synthetic.main.aibk_adapter_item_itemanswer_zw.view.*
import kotlinx.android.synthetic.main.aibk_adapter_item_itemscore.view.*
import kotlinx.android.synthetic.main.aibk_adapter_item_word_stuanswer_zw.view.*
import kotlinx.android.synthetic.main.aibk_fragment_child_zw_analysis_word.view.*

class QuesEvaluationChildFragmentWord (
        val activity: AppCompatActivity,
        val quesEvaluationDetail: QuesEvaluationDetail,
        val index:Int
): ABaseFragment() {

    private var rootView: View? = null

    override fun createLayout(): Int {
        return R.layout.aibk_fragment_child_zw_analysis_word
    }

    override fun initView(view: View?) {
        rootView = view

        //显示序号
        val itemSortIndex = quesEvaluationDetail.ChildList[index].ItemList[0].ItemSortIndex
        rootView!!.TvQuesNumber.text = "$itemSortIndex. "

        //隐藏得分项显示
        rootView!!.LlItemScore.visibility = View.GONE

        //隐藏学生作答
        rootView!!.LlStuAnswer.visibility = View.GONE

        //参考范文
        var childAnswer = quesEvaluationDetail.ChildList[index].ChildAnswer
        // 显示范文单词个数
        var textInputWordCount = LancooMethod.getKeyCount(childAnswer!!.trim(), " ") + 1
        rootView!!.TvItemWordCount.text = Html.fromHtml(
                activity.resources.getString(R.string.aibk_zw_word_count_blue,
                        textInputWordCount
                )
        )
        //显示范文
        WebStyleUtils.showWebViewCssStyle(activity, rootView!!.WvItemAnswer, childAnswer, false)

        //答案解析
        var childAnalysis = quesEvaluationDetail.ChildList[index].ChildAnalysis
        if (childAnalysis.isEmpty()) {
            childAnalysis = activity.getString(R.string.aibk_no_text) //...略
        }
//        rootView!!.TvItemAnalysis.text = LancooMethod.getNewItemAnalysis(childAnalysis)
        CustomTextViewToPicture(activity,rootView!!.TvItemAnalysis,LancooMethod.getNewItemAnalysis(childAnalysis))
    }

}